from Function import Database

database_address = "Database/Data.db"

def getDoneStudentsList(commit_dict: dict, student_list: list) -> list:
    """
    打印已经提交的学生
    输入：已经提交的学生列表，班级学生列表
    输出：已经完成的学生列表
    """
    done_students_list = []
    for item in student_list:
        if item in commit_dict.keys():
            done_students_list.append(item)
    return done_students_list


def getUndoStudentsList(commit_dict: dict, student_list: list) -> list:
    """
    打印未提交的学生
    输入：已经提交的学生列表，班级学生列表
    输出：未完成的学生列表
    """
    undo_students_list = []
    for item in student_list:
        if item not in commit_dict.keys():
            undo_students_list.append(item)
    return undo_students_list


def getAllStudentsDic(commit_dict: dict, studentList: list) -> dict:
    """
    打印所有的学生，并按提交和未提交分类
    输入：已经提交的学生列表，班级学生列表
    输出：包含所有学生的字典
    """
    undo_students_list = getUndoStudentsList(commit_dict, studentList)
    done_students_list = getDoneStudentsList(commit_dict, studentList)
    allStudentsList = {}
    allStudentsList["undo"] = undo_students_list
    allStudentsList["done"] = done_students_list
    return allStudentsList


def nameToID(name_list: list) -> list:
    IDList = []
    # 获取班级学生的信息列表(姓名，学号）
    students_info_list = Database.read_data_to_list(database_address, "students")
    for item in name_list:
        for info in students_info_list:
            if item in info:
                IDList.append(str(info[1]))
    return IDList
